package com.evenmo.hrms.mapper.oldmapper.dynaSqlProvider;

import com.evenmo.hrms.pojo.Job;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

public class JobDynaSqlProvider {
    public String selectByParmams(Map<String, Object> params) {
        return new SQL() {
            {

                SELECT("*");
                FROM("job");
                Object objJob = params.get("job");
                if (objJob != null) {
                    Job job = (Job) objJob;
                    if (job.getName() != null) {
                        WHERE("name=#{job.name}");
                    }
                    if (job.getRemark() != null) {
                        WHERE("remark like concat('%',#{job.remark},'%')");
                    }
                }
                Object objNameParams = params.get("nameLikeParam");
                if (objNameParams != null) {
                    String nameParam = (String) objNameParams;
                    if (nameParam != null) {
                        WHERE("name like concat('%',#{nameLikeParam},'%')");
                    }
                }
                Object objLikeParams = params.get("remarkLikeParam");

                if (objLikeParams != null) {
                    String LikeParams = (String) objLikeParams;
                    if (LikeParams != null) {
                        WHERE("remark like concat('%',#{remarkLikeParam},'%')");
                    }
                }

            }
        }.toString();
    }

    public String updateByParams(Job jobForInfo, Map<String, Object> params) {
        return new SQL() {
            {

                UPDATE("job");
                if (jobForInfo.getName() != null) {
                    SET("name=#{jobForInfo.name}");
                }
                if (jobForInfo.getRemark() != null) {
                    SET("remark=#{jobForInfo.remark}");
                }

                Object objJobConditonn = params.get("conditions");

                if (objJobConditonn != null) {
                    Job job = (Job) objJobConditonn;
                    if (job.getId() != null) {
                        WHERE("id=#{params.conditions.id}");
                    }
                    if (job.getName() != null) {
                        WHERE("name=#{params.conditions.name}");
                    }
                }


            }
        }.toString();
    }

    public String insertByParams(Job job) {
        return new SQL() {
            {
                INSERT_INTO("job");
                if (job.getName() != null) {
                    VALUES("name", "#{name}");
                }
                if (job.getRemark() != null) {
                    VALUES("remark", "#{remark}");
                }


            }
        }.toString();
    }
}
